
/**
*js公有验证操作
*@author  suqian
*@date    2010/9/22
*@package validate
**/

Array.prototype = {
	in_array:function (value){
			for (var i =0;i<this.length;i++){
				if(this[i] == value) return true;
			}
			return false;
	}	
}
String.prototype = {
	trim:function(){
		return this.replace(/(^s*)|(s*$)/g, '');
	}
}
validate = {
	regExp:null,
	isEmpty:function(value){
		if(value === null) return false;
		if(value === 0) return false;
		if (value.trim() === '') return false;
		this.regExp = /^[ ]+$/;
		return !this.regExp.test(value);
	},
	isInt:function(value){
		this.regExp =  /^-?[1-9]+0?[0-9]*$/;
		return this.regExp.test(value);
	},
	isFloat:function(value){
		this.regExp = /^\d+(\.{0,1}\d+){0,1}$/;
		return this.regExp.test(value);
	},
	isEmail:function(email){
		this.regExp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
		return this.regExp.test(email);
	},
	isIdCard:function(idcard){
		this.regExp = /\d{17}[\d|X]|\d{15}/;
		return this.regExp.test(idcard);
		
	},
	isTel:function(tel){
		this.regExp = /(^(0\d{2})?-?(\d{7,8})$)|(^(0\d{3})?-?(\d{7,8})$)|(^(0\d{2})?-?(\d{8})-(\d+)$)|(^(0\d{3})?-?(\d{7})-(\d+)$)/;
		return this.regExp.test(tel);
	},
	isPhone:function(phone){
		var result = true;
		this.regExp = /^\d{11}$/;
		return this.regExp.test(phone);
	},
	isUrl:function(url){
		this.regExp = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
		return this.regExp.test(url);
	},
	isChinese:function(chinese){
		this.regExp = /^[\u4e00-\u9fa5]+/;
		return this.regExp.test(chinese);
	},
	isHtml:function(html){
		this.regExp = /<(.*)>.*|<(.*)\/>/;
	}
}

function verify(verifyType,e,callback){
	var obj;
	if(typeof(e) == 'object'){
		var eArgs = window.event ? window.event : e;
	    obj = eArgs.srcElement ? eArgs.srcElement : eArgs.target;
	}else{
		obj = getObj(e);
	}
	for(var method in validate){
		if(method.toLowerCase() == verifyType.toLowerCase()){
			var func = "validate."+method+"('"+obj.value+"')";
			var result = eval(func);
			callback && callback(result);
			return result;
		}
	}
	return false;
}

function message(id,tips,className){
	var msg = getObj(id);
	msg.innerHTML = tips;
	msg.className = className;
}

function button(id,ifdisabled){
	var obj = getObj(id);
	obj.disabled = ifdisabled;
}